<template>
  <div id="app">
    <router-view v-slot="{ Component }">
      <keep-alive :exclude="['product']">
        <van-config-provider theme="light">
          <component :is="Component" />
        </van-config-provider>
      </keep-alive>
    </router-view>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import { useRouter, RouterView } from 'vue-router'
import { useUserInfoStoreHook } from "@/stores/user";
import { useAuthInfoHook } from '@/utils/request'
import { ssoLoginParams } from "@/service/user";
const router = useRouter()
const state = reactive({
  transitionName: 'slide-left'
})

router.beforeEach((to: any, from: any, next: any) => {
  // 在跳转路由的时候检查租户信息
  if (to.query && to.query.tenantId) {
    const useUserInfoStore: any = useUserInfoStoreHook();
    const authInfo = useAuthInfoHook();
    authInfo.value.tenantId = to.query.tenantId as string;
    localStorage.setItem('TENANTID', authInfo.value.tenantId)
    const data: ssoLoginParams = {
      auth: to.query.auth as string,
      user: to.query.user as string,
      key: to.query.key as string,
      tenantId: authInfo.value.tenantId,
    }
    useUserInfoStore.ssoLogin(data);
    next({
      path: "/home"
    });
  }
  if (to.meta.index > from.meta.index) {
    state.transitionName = 'slide-left' // 向左滑动
  } else if (to.meta.index < from.meta.index) {
    // 由次级到主级
    state.transitionName = 'slide-right'
  } else {
    state.transitionName = ''   // 同级无过渡效果
  }
  next()
})
</script>

<style lang="less">
html,
body {
  height: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
  user-scalable: no;
  touch-action: pan-x pan-y;
}

#app {
  height: 100%;
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  // text-align: center;
  color: #2c3e50;
}

.router-view {
  width: 100%;
  height: auto;
  position: absolute;
  top: 0;
  bottom: 0;
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
}

.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  height: 100%;
  will-change: transform;
  transition: all 500ms;
  position: absolute;
  backface-visibility: hidden;
}

.slide-right-enter {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}

.slide-right-leave-active {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}

.slide-left-enter {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}

.slide-left-leave-active {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}

.van-badge--fixed {
  z-index: 1000;
}

// 去掉滑动条
::-webkit-scrollbar {
  display: none;
}

.text-overflow {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
